home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
LDB171.ARJ
/
EXAMP601.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-12
|
2KB
|
109 lines
// examp601.cpp - link with binder.obj, mutual.obj,
// mint.obj, and mstr.obj
#define bfile "examp601.txt"
#include <string.h>
#include "mint.hpp"
#include "mstr.hpp"
// display integers and strings
void display(MutuaL M)
{
switch (M->ID()) {
case ID_Mint:
cout << ((MinT)M)->I() << endl;
break;
case ID_Mstr:
cout << ((MstR)M)->S() << endl;
break;
default:
cout << "unknown" << endl;
break;
}
}
// sort integers and strings
int mintstrcmp(MutuaL M1, MutuaL M2)
{
// integers sorted to the front
// strings sorted to the rear
if (M1->ID() == ID_Mint)
if (M2->ID() == ID_Mint)
return ((MinT)M1)->I()
- ((MinT)M2)->I();
else
return -1;
else
if (M2->ID() == ID_Mint)
return 1;
else
return strcmp(
((MstR)M1)->S(),
((MstR)M2)->S());
}
main()
{
Mint::RegisterClass();
Mstr::RegisterClass();
MBinder b1;
b1.push(new Mstr("Hello LDB!"));
b1.insQ(new Mstr("Goodbye linked"));
b1.insQ(new Mstr("list programming!"));
b1.insQ(b1.rear());
b1.insQ(new Mstr(
"Line above tests multilinking!"));
for (int i = 3; i; i--)
b1.insQ(new Mint(i));
cout << "\n\nMBinder of streamable integers"
<< " and strings!\n\n";
b1.forEach((BDRapplY)display);
cout << "\n\nPress enter to continue ...";
cin.get();
b1.setComP((BDRcomP)mintstrcmp);
Binder::RegisterComP((BDRcomP)mintstrcmp);
(void) b1.save(bfile);
b1.allDel();
MBinder b2(bfile);
cout << "\nStreamed and "
<< "reloaded MBinder with "
<< "multiple links maintained "
<< "\nand sorted with streamed "
<< "compare fnc, ints in front:"
<< " \n";
Restream();
// Don't load again from
// any stream without
// restreaming StreamRegistry!!!
b2.sort();
b2.forEach((BDRapplY)display);
return 0;
}